home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
59267
/
59267.xpi
/
chrome
/
content
/
autohidetabbar.js
next >
Wrap
Text File
|
2010-01-25
|
7KB
|
234 lines
var autoHideTabBar12 = {
start : function()
{
this.prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
this.readPrefs();
var theBrowser = getBrowser();
// Move the tab bar to the bottom?
if (this.isTabbarAtBottom)
{
// Move tab bar to the bottom of the main window.
var pc = theBrowser.mPanelContainer;
pc.parentNode.appendChild(theBrowser.mStrip);
pc.parentNode.appendChild(theBrowser.mTabDropIndicatorBar);
}
// Add an item to the context menu of the tabbar.
this.addContextMenu();
// add event handlers for tabbar.
// mouse is out of tab bar.
theBrowser.mStrip.addEventListener("mouseout",
function(evt){ autoHideTabBar12.tryHideTabBar(); }, false);
// the following 4 events imply the mouse is in tab bar.
theBrowser.mStrip.addEventListener("mouseover",
function(evt){ autoHideTabBar12.isMouseInTabbar = true; }, false);
theBrowser.mStrip.addEventListener("mousemove",
function(evt){ autoHideTabBar12.isMouseInTabbar = true; }, false);
theBrowser.mStrip.addEventListener("click",
function(evt){ autoHideTabBar12.isMouseInTabbar = true; }, false);
theBrowser.mStrip.addEventListener("dragenter",
function(evt){ autoHideTabBar12.isMouseInTabbar = true; }, false);
// when right click on the tab-bar.
// the following 2 events happen when tab context menu popup and hide.
theBrowser.mStrip.addEventListener("popupshowing",
function(evt){ autoHideTabBar12.isContextMenuOn = true; }, false);
theBrowser.mStrip.addEventListener("popuphidden",
function(evt)
{
autoHideTabBar12.isContextMenuOn = false;
autoHideTabBar12.tryHideTabBar();
},
false);
// mouse is in the page. definitely out of tab bar.
theBrowser.mPanelContainer.addEventListener("mousemove",
function(evt){ autoHideTabBar12.tryHideTabBar(); }, false);
},
// Add an item to the context menu of the tabbar.
addContextMenu : function()
{
// See firefox source code "tabbrowser.xml" - the 2nd child
// of <anonid="strip"> is <anonid="tabContextMenu">
var contxtMenu = getBrowser().mStrip.childNodes[1];
if (contxtMenu)
{
contxtMenu.appendChild(document.createElement("menuseparator"));
contxtMenu.appendChild(document.getElementById("ahtb12ContextAutohide"));
}
},
// When mouse move from one tab to another inside the tab-bar,
// mouseout and mouseover are fired and bubbled to the Strip.
// So we delay hide-tabbar upon mouseout to see whether mouseover
// will be received.
tryHideTabBar : function()
{
this.isMouseInTabbar = false;
if (getBrowser().getStripVisibility())
{
// tab bar visible, go hide it, but postpone a little.
setTimeout(function() { autoHideTabBar12.hideTabBar(); }, 800);
}
},
// Time to hide the tab-bar.
hideTabBar : function()
{
// feature is enabled?
if (!this.isEnabled)
return;
// Wont hide when user invoke context menu.
if (this.isContextMenuOn)
return;
// mouse back to tab-bar again?
if (this.isMouseInTabbar)
return;
// Now, we can hide it.
var theBrowser = getBrowser();
// get a fake tabbar for restoring the real tabbar.
var fakeTabbar = document.getElementById(this.fakeTabbarId);
if (!fakeTabbar)
{
// Add a fake tab-bar.
fakeTabbar = document.createElement("toolbar");
fakeTabbar.id = this.fakeTabbarId;
fakeTabbar.setAttribute("customizable", "false");
fakeTabbar.style.minHeight = "3px";
fakeTabbar.style.height = "3px";
var strp = theBrowser.mStrip;
strp.parentNode.insertBefore(fakeTabbar, strp);
fakeTabbar.addEventListener("mouseover",
function() { autoHideTabBar12.showTabBar(); }, false);
fakeTabbar.addEventListener("dragenter",
function() { autoHideTabBar12.showTabBar(); }, false);
}
if (fakeTabbar)
{
// show the fake tab-bar.
fakeTabbar.setAttribute("moz-collapsed", "false");
// hide the tab-bar
//this.animateUpTabbar();
theBrowser.setStripVisibilityTo(false);
}
},
showTabBar : function()
{
var theBrowser = getBrowser();
// show the tab-bar
// if there is only 1 tab and "Always show the tab bar" option
// is not checked, do not show the tab bar.
if (theBrowser.tabContainer.childNodes.length > 1 ||
!this.prefService.getBoolPref("browser.tabs.autoHide"))
{
theBrowser.setStripVisibilityTo(true);
this.isMouseInTabbar = true;
}
var fakeTabbar = document.getElementById(this.fakeTabbarId);
if (fakeTabbar)
{
// hide the fake tab-bar
fakeTabbar.setAttribute("moz-collapsed", "true");
}
},
readPrefs : function()
{
// Get the preferences
myprefs = this.prefService.getBranch("extensions.autohidetabbar.");
this.isEnabled = myprefs.getBoolPref("isEnabled");
this.isTabbarAtBottom = myprefs.getBoolPref("isTabbarAtBottom");
// set the context menu.
document.getElementById("ahtb12ContextAutohide").setAttribute(
"checked", this.isEnabled ? "true" : "false");
// show/hide tab bar.
if (this.isEnabled)
this.tryHideTabBar();
else
this.showTabBar();
},
toggleAutoHide : function()
{
this.isEnabled = !this.isEnabled;
// set the context menu.
document.getElementById("ahtb12ContextAutohide").setAttribute(
"checked", this.isEnabled ? "true" : "false");
// save to Preferences.
var myprefs = this.prefService.getBranch("extensions.autohidetabbar.");
var defprefs = this.prefService.getDefaultBranch("extensions.autohidetabbar.");
var prefname = "isEnabled";
if (defprefs.getBoolPref(prefname) != this.isEnabled)
myprefs.setBoolPref(prefname, this.isEnabled);
else if (myprefs.prefHasUserValue(prefname)) // equal to default.
myprefs.clearUserPref(prefname); // clear user's setting.
},
// Not good. Not used.
XXanimateUpTabbar : function()
{
if (0 == this.animationAmount)
this.animationAmount = 2;
if (this.animationAmount >= getBrowser().mStrip.boxObject.height)
{
this.animationAmount = 0;
return;
}
this.animationAmount *= 2;
getBrowser().mStrip.style.marginTop = (this.animationAmount * -1) + "px";
setTimeout(function() { autoHideTabBar12.animateUpTabbar(); }, 80);
},
isEnabled : true,
fakeTabbarId : "ahtb12FakeTabbar",
isContextMenuOn : false,
isMouseInTabbar : false,
isTabbarAtBottom : false,
animationAmount : 0, // not used.
prefService : null
};
// delay a little bit to make sure that the browser is up and running.
setTimeout(function(){ autoHideTabBar12.start(); }, 2000);